package cn.estore.util;
/*定义数据库链接类*/

import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnection {
    /*加载数据库驱动*/
    private String dbDriver = "com.mysql.cj.jdbc.Driver";
    /*指定数据库连接字符串*/
    private String url = "jdbc:mysql://localhost:3306/estoredb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8";
    public Connection connection = null;
    public DBConnection() {
        try {
            Class.forName(dbDriver); // 加载数据库驱动
            connection = DriverManager.getConnection(url, "estore", "Pass2023");
            // 加载数据库
        }catch (Exception ex) {
            System.out.println("数据库加载失败");
            System.out.println(ex.getMessage());
        }
    }
}
